package com.tencent.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.tencent.User;
import com.tencent.feign.OrderFallBack;
import com.tencent.feign.SentinelFallBack;
import com.tencent.feign.UserService;
import com.tencent.sentinel.OrderBlockHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private UserService userService;

    @GetMapping("/findUserById/{id}")
    @SentinelResource(value = "order-findUserById",
            blockHandler = "findUserByIdBlockHandler",
            blockHandlerClass = OrderBlockHandler.class,
            fallback = "findUserByIdFallBack",
            fallbackClass = SentinelFallBack.class)
    public User findUserById(@PathVariable("id") Long id){
        int a = 1/0;
        return userService.findUserById(id);
    }
}
